package offer;
//二进制中1的个数
public class T11 {
    public int NumberOf1(int n) {
        if (n==-2147483648) return 1;
        int ans = 0;
        int num = 0;
        boolean flag = false;
        boolean flag_zero  = true;
        if (n<0) {
            flag = true;
            n=-n;
        }
        while (n>0) {

            if (flag_zero&&(n&1)==0) num++;
            else flag_zero = false;
            ans+= (n&1);
            n>>=1;

        }

        if (flag) return 32-ans+1-num;
        else return ans;
    }
    public static void main ( String[] args) {

        System.out.println(new T11().NumberOf1(-2147483648));
    }
}
